package com.xoms.admin.persist.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.xoms.admin.model.ProStockBean;
import com.xoms.admin.model.vo.ProStockVo;
import com.xoms.admin.persist.dao.ProStockDao;
import com.xoms.util.StringUtil;

@Repository
public class ProStockImpl extends BaseImpl implements ProStockDao {
	
	final String NAME_SPACE = NAME_SPACE_HEADER + ".ProStockMapper";

	@Override
	public List<ProStockVo> selectStocks(String key, int page, int pagesize, String storeHouseId) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("start", page * pagesize);
		params.put("length", pagesize);
		if (!StringUtil.isEmpty(key)) {
			params.put("key", key);
		}
		if (!StringUtil.isEmpty(storeHouseId)) {
			params.put("storeHouseId", storeHouseId);
		}
		return sqlSessionTemplate.selectList(NAME_SPACE + ".selectList", params);
	
	}

	@Override
	public int selectCount(String storeHouseId, String key) {
		Map<String, Object> params = new HashMap<String, Object>();
		if (!StringUtil.isEmpty(key)) {
			params.put("key", key);
		}
		if (!StringUtil.isEmpty(storeHouseId)) {
			params.put("storeHouseId", storeHouseId);
		}
		return sqlSessionTemplate.selectOne(NAME_SPACE + ".selectCount", params);
	
	}

	@Override
	public int selectStore2Pro(String pid) {
		return sqlSessionTemplate.selectOne(NAME_SPACE + ".selectStore2Pro", pid);
	}

	@Override
	public int replaceStocks(List<ProStockBean> newStocks) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("list", newStocks);
 		return sqlSessionTemplate.update(NAME_SPACE +".replaceStocks", params);
	}
}
